package com.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.common.Result;
import com.example.dao.AddVenderListDTO;
import com.example.entity.HnyyPurRebateList;
import com.example.entity.HnyyPurRebateVender;
import com.example.service.ProtocolService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/protocol")
public class ProtocolController {
    @Autowired
    private ProtocolService protocolService;
    @GetMapping("/addPolicy")
    public Result addPolicy(HttpServletRequest request, @RequestParam String venderNo, @RequestParam String memo){
        String comPartyId = (String) request.getAttribute("comPartyId");
        String user = (String) request.getAttribute("saler");
        Long x=protocolService.addPolicy(comPartyId,user,venderNo,memo);
        return Result.success(x);
    }
    @PostMapping("/addVenderList")
    public Result addVenderList(@RequestBody AddVenderListDTO addVenderListDTO){
        System.out.println("addVenderListDTO=======>"+JSONObject.toJSONString(addVenderListDTO));
        int x=0;
        for(Object id:addVenderListDTO.getListId()){
           x += protocolService.addVenderList(addVenderListDTO.getVenderId(),(String) id);
        }
        return Result.success(x);
    }
    @GetMapping("/addVenderFile")
    public Result addVenderFile(HttpServletRequest request, @RequestParam String venderId, @RequestParam String fileName){
        String comPartyId = (String) request.getAttribute("comPartyId");
        String user = (String) request.getAttribute("saler");
        int x=protocolService.addVenderFile(comPartyId,user,venderId,fileName);
        return Result.success(x);
    }

    @GetMapping("/getImg")
    public Result getImg(@RequestParam String id){
        String url=protocolService.getImg(id);
        return Result.success(url);

    }



}
